import request from '@/utils/request'

export function add(data) {
  return request({
    url: '/api/tasks',
    method: 'post',
    data
  })
}

export function del(ids) {
  return request({
    url: '/api/tasks',
    method: 'delete',
    data: ids
  })
}

export function edit(data) {
  return request({
    url: '/api/tasks',
    method: 'put',
    data
  })
}

export function run(data) {
  return request({
    url: '/api/tasks/exec/run',
    method: 'put',
    data: data
  })
}

export function downloadFile(id, token) {
  return request({
    url: `/api/download/${id}?token=${token}`,
    method: 'get',
    responseType: 'blob'
  })
}

export function getSourceFiles() {
  return request({
    url: '/api/upload/task/data?page=0&size=100&sort=id,desc',
    method: 'get'
  })
}

export default { del, run, add, edit, downloadFile, getSourceFiles }
